package org.trademarket.trader;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;
import org.trademarket.trader.domain.Proposal;

@Component
public class TradeTrackerService {
	private final static Logger LOGGER = LoggerFactory.getLogger(TradeTrackerService.class);
	
	private JmsTemplate jmsTemplate = null;
	
	public void send(final Proposal proposal) {
		jmsTemplate.send(new MessageCreator() {

			@Override
			public Message createMessage(Session session) throws JMSException {
				return session.createTextMessage(proposal.toString());
			}
		});
		LOGGER.info("Proposal was sent: {}", proposal);
	}

	@Autowired
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

}
